// pages/Index/shopActive/group/index.js
const controllers = require('../../../controllers/controllerIndex').controller
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    groupList: [],
    pendbigimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/card_20@2x.png',
    overbigimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/card_21@2x.png',
    nobigimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/card_22@2x.png',
    pendsmallimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/index/img/but_60@2x.png',
    oversmallimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/index/img/but_61@2x.png',
    nosmallimg: 'https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/image/index/img/but_60@2x.png',
    pageNumber: 1,
    pageSize: 10,
    isEnd: false,
  },
  //获取列表
  groupList() {
    //获取拼团列表
    controllers.getGroupList({
      pageNumber: this.data.pageNumber,
      pageSize: this.data.pageSize,
      shopId: wx.getStorageSync('shopId')
    }).then(res => {
      if (res.data.list.length != 0) {
        this.setData({
          groupList: this.data.groupList.concat(res.data.list)
        })
      }
      if (res.data.lastPage) {
        this.setData({
          isEnd: true
        })
      }
    })
  },
  //跳转到拼团详情页
  toGroupDetail(e) {
    wx.navigateTo({
      url: '/pages/Index/shopActive/group/detail?id=' + e.currentTarget.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      groupList: [],
      isEnd: false,
      pageNumber: 1,
    })
    this.groupList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isEnd) {
      return;
    } else {
      this.setData({
        pageNumber: this.data.pageNumber + 1,
      });
      this.groupList()
    }
  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})